package com.fanyouzhao.eshop.portal.service.impl;

import com.fanyouzhao.eshop.core.pojo.Banner;
import com.fanyouzhao.eshop.portal.daoMongo.BannerRepository;
import com.fanyouzhao.eshop.portal.service.BannerService;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * @author: fanyouzhao
 * @date: 17:35 2021/6/30
 */
@Service("bannerService")
public class BannerServiceImpl implements BannerService {

    @Resource
    BannerRepository bannerRepository;

    @Override
    public List<Banner> findAllByPosition(String postion) {
        Banner banner = new Banner();
        banner.setPosition(postion);
        Example<Banner> of = Example.of(banner);
        Sort id = Sort.by(Sort.Direction.ASC, "id");
        return bannerRepository.findAll(of,id);
    }

    @Override
    public void insertOrUpdate(Banner banner) {
        Banner insert = bannerRepository.insert(banner);
    }

    @Override
    public Banner selectOne(Banner banner) {
        Example<Banner> of = Example.of(banner);
        Optional<Banner> one = bannerRepository.findOne(of);
        return null;
    }

    @Override
    public void delete(Banner banner) {
        bannerRepository.delete(banner);
    }
}
